﻿using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace Blog.System.BackgroundJobs.Jobs
{
    public class HelloWorldJob : BackgroundService
    {
        private readonly ILogger<HelloWorldJob> _logger;
        public HelloWorldJob(ILogger<HelloWorldJob> logger) 
        {
            _logger = logger;
        }
        protected override async Task ExecuteAsync(CancellationToken stoppingToken) 
        {
            while (!stoppingToken.IsCancellationRequested) 
            {
                var msg = $"CurrentTime: {DateTime.Now}，Hello World!";

                Console.WriteLine(msg);

                _logger.LogInformation(msg);

                await Task.Delay(1000, stoppingToken);
            }
        }
    }
}
